package com.lry.basic.jvm.asm.transform_class.demo1;

import aj.org.objectweb.asm.ClassReader;
import aj.org.objectweb.asm.ClassVisitor;
import aj.org.objectweb.asm.ClassWriter;
import com.lry.basic.jvm.asm.utils.FileUtils;

import static aj.org.objectweb.asm.Opcodes.ASM4;

public class Test {

    public static void main(String[] args) {
        String relativePath = "com/lry/basic/jvm/asm/transform_class/demo1/HelloWorld.class";
        String filePath = FileUtils.getFilePath(relativePath);
        byte[] b = FileUtils.readBytes(filePath);

        ClassReader cr = new ClassReader(b);

        ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);

        ClassVisitor cv = new ChangeVersionVisitor(ASM4,cw);

        cr.accept(cv,ClassReader.SKIP_DEBUG|ClassReader.SKIP_FRAMES);

        byte[] b2 = cw.toByteArray();

        FileUtils.writeBytes(filePath, b2);
    }
}
